﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using yunbo.Model.SM;
using yunbo.Model.SSM;
using yunbo.Repositorys.SMRepositorys;
using yunbo.Repositorys.SSMRepositorys;

namespace yunbo.Controllers.SMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class WLDBController : ControllerBase
    {
        WLDBRepository wldbRepositorys = new WLDBRepository();
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFYwldb")]
        public IActionResult GetFYwldb(int PageNumber, int PageSize)
        {
            FYwldb wldb = wldbRepositorys.GetFYwldb(PageNumber, PageSize);
            return Ok(wldb);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("Postwldb")]
        public IActionResult Postwldb(TJwldb tjwldb)
        {
            //// 获取当前时间，并格式化为字符串
            //string currentTime = DateTime.Now.ToString("yyyyMMdd");

            //// 生成一个四位随机数
            //Random random = new Random();
            //int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            //string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            //// 组合当前时间和随机数生成ID
            //string id = $"wldb{currentTime}{randomNumberString}";
            wldb wldb = new wldb()
            {
                wldb_code = tjwldb.wldb_code,
                wldb_bz=tjwldb.wldb_bz,
                wldb_state = 1,
                wldb_dblx=tjwldb.wldb_dblx,
                wldb_jhdbsj=tjwldb.wldb_jhdbsj,
                rkw_code=tjwldb.rkw_code,
                ckw_code=tjwldb.ckw_code,
                ckb_code="",
                rk_code="",
                create_by=tjwldb.create_by,
                create_time=DateTime.Now
            };
            bool rs = wldbRepositorys.Postwldb(wldb) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatewldb")]
        public IActionResult Updatewldb(XGwldb xgwldb)
        {
            wldb wldb = new wldb()
            {
                wldb_id = xgwldb.wldb_id,
                wldb_bz = xgwldb.wldb_bz,
                wldb_dblx = xgwldb.wldb_dblx,
                wldb_jhdbsj = xgwldb.wldb_jhdbsj,
                rkw_code = xgwldb.rkw_code,
                update_by = xgwldb.update_by,
                update_time = DateTime.Now
            };
            bool i = wldbRepositorys.Updatewldb(wldb) > 0;
            return Ok(i);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatewldbzt")]
        public IActionResult Updatewldbzt(int state, string code, string? ckb_code)
        {
            bool i = wldbRepositorys.Updatewldbzt(state,code, ckb_code) > 0;
            return Ok(i);
        }
        //string code, string? rk_code
        /// <summary>
        /// 修改入库
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatewldbrk")]
        public IActionResult Updatewldbrk(string code, string? rk_code)
        {
            bool i = wldbRepositorys.Updatewldbrk(code, rk_code) > 0;
            return Ok(i);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatewldbrkzt")]
        public IActionResult Updatewldbrkzt(int state, string code, string? rk_code)
        {
            bool i = wldbRepositorys.Updatewldbrkzt(state, code, rk_code) > 0;
            return Ok(i);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        [HttpPut("Updatezt")]
        public IActionResult Updatezt(int state, string code)
        {
            bool i = wldbRepositorys.Updatezt(state, code) > 0;
            return Ok(i);
        }
        /// <summary>
        /// 分页条件查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFYTJwldb")]
        public IActionResult GetFYTJwldb(int PageNumber, int PageSize,string? lx)
        {
            FYwldb wldb = wldbRepositorys.GetFYTJwldb(PageNumber, PageSize,lx);
            return Ok(wldb);
        }
    }
}
